/*
 * @Author: zh
 * @Date: 2024-12-06 14:01:08
 * @LastEditors: zh
 * @LastEditTime: 2024-12-09 14:32:07
 * @Description: 
 */
import type { PluginOption } from 'vite'
import compressPlugin from 'vite-plugin-compression'

// 配置压缩插件
export function configCompressPlugin({
    compress,
    deleteOriginFile = false,
}: {
    // 压缩类型
    compress: string;
    // 是否删除源文件
    deleteOriginFile?: boolean;
}): PluginOption[] {
    const compressList = compress.split(',');

    const plugins: PluginOption[] = [];
    // gzip压缩
    if (compressList.includes('gzip')) {
        plugins.push(
            compressPlugin({
                ext: '.gz',
                deleteOriginFile,
            })
        );
    }

    // brotli 压缩
    if (compressList.includes('brotli')) {
        plugins.push(
            compressPlugin({
                ext: '.br',
                algorithm: 'brotliCompress',
                deleteOriginFile,
            })
        );
    }
    return plugins
}